/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kungkhies.persistence.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author clayton
 */
@Entity 
@Table(name = "knode_activity")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "KnodeActivity.findAll", query = "SELECT k FROM KnodeActivity k"),
    @NamedQuery(name = "KnodeActivity.findByKimplId", query = "SELECT k FROM KnodeActivity k WHERE k.knodeActivityPK.kimplId = :kimplId"),
    @NamedQuery(name = "KnodeActivity.findByKnodeId", query = "SELECT k FROM KnodeActivity k WHERE k.knodeActivityPK.knodeId = :knodeId"),
    @NamedQuery(name = "KnodeActivity.findByKnodeType", query = "SELECT k FROM KnodeActivity k WHERE k.knodeType = :knodeType"),
    @NamedQuery(name = "KnodeActivity.findByActivityId", query = "SELECT k FROM KnodeActivity k WHERE k.knodeActivityPK.activityId = :activityId")
})
public class KnodeActivity implements Serializable 
{
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected KnodeActivityPK knodeActivityPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 8)
    @Column(name = "knode_type")
    private String knodeType;
    @JoinColumn(name = "activity_id", referencedColumnName = "activity_id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Activity activity;
    @JoinColumns(
    {
        @JoinColumn(name = "kimpl_id", referencedColumnName = "kungkhie_id", insertable = false, updatable = false),
        @JoinColumn(name = "knode_id", referencedColumnName = "knode_id", insertable = false, updatable = false)
    })
    @ManyToOne(optional = false)
    private KungkhieKnode kungkhieKnode;

    public KnodeActivity()
    {
    }

    public KnodeActivity(KnodeActivityPK knodeActivityPK)
    {
        this.knodeActivityPK = knodeActivityPK;
    }

    public KnodeActivity(KnodeActivityPK knodeActivityPK, String knodeType)
    {
        this.knodeActivityPK = knodeActivityPK;
        this.knodeType = knodeType;
    }

    public KnodeActivity(long kimplId, long knodeId, long activityId)
    {
        this.knodeActivityPK = new KnodeActivityPK(kimplId, knodeId, activityId);
    }

    public KnodeActivityPK getKnodeActivityPK()
    {
        return knodeActivityPK;
    }

    public void setKnodeActivityPK(KnodeActivityPK knodeActivityPK)
    {
        this.knodeActivityPK = knodeActivityPK;
    }

    public String getKnodeType()
    {
        return knodeType;
    }

    public void setKnodeType(String knodeType)
    {
        this.knodeType = knodeType;
    }

    public Activity getActivity()
    {
        return activity;
    }

    public void setActivity(Activity activity)
    {
        this.activity = activity;
    }

    public KungkhieKnode getKungkhieKnode()
    {
        return kungkhieKnode;
    }

    public void setKungkhieKnode(KungkhieKnode kungkhieKnode)
    {
        this.kungkhieKnode = kungkhieKnode;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (knodeActivityPK != null ? knodeActivityPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof KnodeActivity))
        {
            return false;
        }
        KnodeActivity other = (KnodeActivity) object;
        if ((this.knodeActivityPK == null && other.knodeActivityPK != null) || (this.knodeActivityPK != null && !this.knodeActivityPK.equals(other.knodeActivityPK)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "com.kungkhies.persistence.entities.KnodeActivity[ knodeActivityPK=" + knodeActivityPK + " ]";
    }

}
